package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IMemberReservationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 预约信息Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags = "预约信息相关接口")
public class MemberReservationController extends BaseController {
    @Autowired
    private IMemberReservationService memberReservationService;

    /**
     * 查询当天取消预约数量
     * @return
     */
    @GetMapping("/cancelled-count")
    @ApiOperation("查询当天取消预约数量")
    public R<Integer> getCancelledReservationCount() {
        Integer times = memberReservationService.getCancelledReservationCount();
        return R.ok(times);
    }

    /**
     * 查询每个时间段剩余预约次数
     * @return
     */
    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping("/countByTime")
    public AjaxResult countByTime(@ApiParam(value = "时间段") Long time){
        List<Map<String, Object>> result = memberReservationService.countByTime(time);
        return AjaxResult.success(result);
    }

    /**
     * 新增预约
     * @param reservation
     * @return
     */
    @ApiOperation("新增预约")
    @PostMapping
    public AjaxResult add(@RequestBody Reservation reservation){
        memberReservationService.saveReservation(reservation);
        return AjaxResult.success();
    }

    /**
     * 分页查询预约信息
     * @param reservation
     * @return
     */
    @ApiOperation("分页查询预约信息")
    @GetMapping("/page")
    public R<TableDataInfo<Reservation>> page(Reservation reservation){
        startPage();
        List<Reservation> list = memberReservationService.seleltReservationList(reservation);
        return R.ok(getDataTable(list));
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public AjaxResult cancelReservation(@ApiParam(value = "预约ID", required = true) @PathVariable Long id){
        memberReservationService.cancelReservation(id);
        return AjaxResult.success();
    }



}